import path from 'path';
import fs from 'fs';

const uploadFolder = path.join(__dirname, '../public');
const imageFolder = path.join(uploadFolder, 'image');
const excelFolder = path.join(uploadFolder, 'excel');
const Folder = {
  userPhoto: path.join(imageFolder, 'userPhoto'),
  'zxwms_image': path.join(imageFolder, 'zxwms'),
  'zxwms_shipment': path.join(excelFolder, 'zxwms', 'shipment'),
  'reimbursement_image': path.join(imageFolder, 'reimbursement'),
  'reimbursement_excel': path.join(excelFolder, 'reimbursement'),
};

/**
 * CreateFolder
 * @author imsunhao
 * @createTime 2017-12-1 13:50:19
 * @description 确保目录存在
 * @param folder
 */
function CreateFolder (folder) {
  try {
    fs.accessSync(folder);
  } catch (e) {
    fs.mkdirSync(folder);
  }
}

for (let index in Folder) {
  if (Folder.hasOwnProperty(index)) {
    CreateFolder(Folder[index]);
  }
}
export {
  uploadFolder,
  imageFolder,
  Folder,
};
